package com.ocom.oauth.auth.app;

import com.ocom.oauth.auth.CustomAbstractTokenGranter;
import java.util.Map;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

/**
 *
 *  说明：
 *    验证码
 *    定义验证码具体逻辑
 */
public class AppCampusTokenGranter extends CustomAbstractTokenGranter {

    private static final String SMS_AUTH = "app_campus";

    private final AppCampusUserDetailService appCampusUserDetailService;

    public AppCampusTokenGranter(AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, AppCampusUserDetailService appCampusUserDetailService) {
        super(tokenServices, clientDetailsService, requestFactory, SMS_AUTH);
        this.appCampusUserDetailService = appCampusUserDetailService;
    }

    @Override
    protected UserDetails getUserDetails(Map<String, String> parameters) {
        String phone = parameters.get("phoneNum");
        String code = parameters.get("smsCode");
        return appCampusUserDetailService.loadByNameAndCode(phone,code);
    }
}
